let envents = new Map()
function addLententFuns(id, cb) {
    envents.set(id, cb)
    window.addEventListener('message', envents.get(id))
}
function removeLententFuns(id) {
    window.removeEventListener('message', envents.get(id))
    envents.delete(id)
}

export const cheackPageOpenStatus = async (urls) => {
    window.postMessage({
        type_urs: 'wtbg',
        data: urls || ['https://compass.jinritemai.com/'],
        type_page: 'pageMeat',
        method: 'check_url_open'
    })
    return new Promise((resolve, reject) => {
        removeLententFuns('check_url_open')
        addLententFuns('check_url_open', (e) => {
            if (e.data.type_urs === 'wtbg' && e.data.api === "check_url_open" && e.data.method == "send_dly_all") {
                resolve(e.data.data)
            }
        })
    })

}
